/*本模块功能:虚机销毁
        编写者:杨锡君
        编写时间:2018.06.26
        */
$(function(){
    var Alert1 = new Alert;
    var loading1 = new Loading();//监控全局ajax添加loading
    loading1.init();
    var index={
        init:function(){
            this.bind();
        },
        bind:function(){
            var self=this;
            self.load();
            $(document).off("click","#sex input").on("click","#sex input",function(){

                $(this).next("label").addClass("checked").siblings("label").removeClass("checked");
            });
            $(".preservation").off("click").click(function(){//点击提交
                self.delivery();
            });

        },
        load:function(){//加载页面基本信息
            $.ajax({
                type: "get",
                url: "manage/config/query",
                async: true,
                success: function(msg) {
                    if(msg.code == 200){
                        var msgNew = msg.data;
                        if(msgNew.containerDeleted==true){
                            $("#sex label").eq(1).addClass("checked").siblings("label").removeClass("checked");
                        }
                        if(msgNew.containerDeleted==false){
                            $("#sex label").eq(0).addClass("checked").siblings("label").removeClass("checked");
                        }
                    }
                },
                error: function(data, status, xhr) {
                    var json = JSON.stringify({
                        "pageName": "error"
                    });
                    window.location.href = "skipPage?jsonStr=" + json;

                }
            });
        },
        delivery:function(){//点击提交
            var flag = $(".checked").attr("num");
            if(flag == 1){
                flag = true;
            }else{
                flag = false;
            }
            var json=JSON.stringify({
                "containerDeleted":flag
            });
            loading1.show();
            $.ajax({
                type: "post",
                url: "manage/config/update",
                async: true,
                dataType:'JSON',
                contentType:'application/json',
                data:json,
                success: function(msg) {
                    loading1.hide();
                    if(msg.code == 200){
                        Alert1.content = "设置成功";
                        Alert1.success = function () {
                            window.location.reload(true);
                        };
                        Alert1.init();
                        Alert1.show();
                    }else{
                        Alert1.content = msg.message;
                        Alert1.init();
                        Alert1.show();
                    }
                },
                error: function(data, status, xhr) {
                    var json = JSON.stringify({
                        "pageName": "error"
                    });
                    window.location.href = "skipPage?jsonStr=" + json;

                }
            });
        }

    };
    index.init();
});
